package com.yanfei.zero.infrastructure.mq;

import java.io.IOException;
import java.util.Map;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import com.rabbitmq.client.Channel;
import com.yanfei.zero.infrastructure.config.DirectRabbitConfig;


@Component
@RabbitListener(queuesToDeclare = @Queue(DirectRabbitConfig.TOPIC_EXCHANGE_QUEUE_A))
public class OrderDelayListener {

    @RabbitHandler
    public void process(Map<String, Object> map,Channel channel,Message msg) throws IOException {
    	// 1 查询订单状态
    	
    	// 2判定是否已经支付
    	
    	// 2.1 已支付 则修改订单状态为已支付
    	
    	// 2.2 未支付 判定订单是否存在延迟时间（多个延迟时间） 存在重发延迟消息  不存在取消订单
    	long deliverTag = msg.getMessageProperties().getDeliveryTag();
    	try {
    		channel.basicAck(deliverTag,false);
		} catch (IOException e) {
			e.printStackTrace();
		
		}
        System.out.println("队列[" + DirectRabbitConfig.TOPIC_EXCHANGE_QUEUE_A + "]收到消息：" + map.toString());
    }
}
